//
//  HwwCreateManager.m
//  huangwenwuSDKDemo
//
//  Created by huangwenwu on 2020/3/7.
//  Copyright © 2020 黄文武. All rights reserved.
//

#import "HwwCreateManager.h"

@interface HwwCreateManager()

@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UITextField *textfield;

@end
@implementation HwwCreateManager

- (HwwCreateManager *)initWithLabel:(UILabel *)label
{
    if (self = [super init]) {
        if (!self) {
            return nil;
        }
        self.label = label;
    }
    
    return self;
}

- (HwwCreateManager *)initWithImageView:(UIImageView *)imageView
{
    if (self = [super init]) {
        
        if (!self) {
            return nil;
        }
        self.imageView = imageView;
    }
    
    return self;
}

- (HwwCreateManager *)initWithButton:(UIButton *)button
{
    if (self = [super init]) {
        if (!self) {
            return nil;
        }
        self.button = button;
    }
    
    return self;
}

- (HwwCreateManager *)initWithTextField:(UITextField *)textfield
{
    if (self = [super init]) {
        if (!self) {
            return nil;
        }
        self.textfield = textfield;
    }
    
    return self;
}
//************************************************************************************************************************

- (HwwCreateManager * _Nonnull (^)(CGFloat))cornerRadius
{
    return ^(CGFloat cornerRadius)
    {
        if (self.label) {
            self.label.layer.cornerRadius = cornerRadius;
            self.label.layer.masksToBounds = YES;
        }
        if (self.imageView) {
            self.imageView.layer.cornerRadius = cornerRadius;
            self.imageView.layer.masksToBounds = YES;
        }
        if (self.button) {
            self.button.layer.cornerRadius = cornerRadius;
            self.button.layer.masksToBounds = YES;
        }
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(CGFloat))alpha
{
    return ^(CGFloat alpha)
    {
        if (self.label) {
            self.label.alpha = alpha;
        }
        if (self.imageView) {
            self.imageView.alpha = alpha;
        }
        if (self.button) {
            self.button.alpha = alpha;
        }
        if (self.textfield) {
            self.textfield.alpha = alpha;
        }
        
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(CGRect frame))frame
{
    return ^(CGRect frame)
    {
        if (self.label) {
            self.label.frame = frame;
        }
        if (self.imageView) {
            self.imageView.frame = frame;
        }
        if (self.button) {
            self.button.frame = frame;
        }
        if (self.textfield) {
            self.textfield.frame = frame;
        }
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(NSInteger tag))tag
{
    return ^(NSInteger tag)
    {
        if (self.label) {
            self.label.tag = tag;
        }
        if (self.imageView) {
            self.imageView.tag = tag;
        }
        if (self.button) {
            self.button.tag = tag;
        }
        if (self.textfield) {
            self.textfield.tag = tag;
        }
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIColor * _Nonnull borderColor))borderColor
{
    return ^(UIColor *borderColor)
    {
        if (self.label) {
            self.label.layer.borderColor = borderColor.CGColor;
        }
        if (self.imageView) {
            self.imageView.layer.borderColor = borderColor.CGColor;
        }
        if (self.button) {
            self.button.layer.borderColor = borderColor.CGColor;
        }
        if (self.textfield) {
            self.textfield.layer.borderColor = borderColor.CGColor;
        }
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(CGFloat))borderWidth
{
    return ^(CGFloat borderWidth)
    {
        if (self.label) {
            self.label.layer.borderWidth = borderWidth;
        }
        if (self.imageView) {
            self.imageView.layer.borderWidth = borderWidth;
        }
        if (self.button) {
            self.button.layer.borderWidth = borderWidth;
        }
        if (self.textfield) {
            self.textfield.layer.borderWidth = borderWidth;
        }
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIColor * _Nonnull))backgroundColor
{
    return ^(UIColor *backgroundColor)
    {
        if (self.label) {
            self.label.backgroundColor = backgroundColor;
        }
        if (self.imageView) {
            self.imageView.backgroundColor = backgroundColor;
        }
        if (self.button) {
            self.button.backgroundColor = backgroundColor;
        }
        if (self.textfield) {
            self.textfield.backgroundColor = backgroundColor;
        }
        return self;
    };
}

//***********************************************************************************************************************************************

- (HwwCreateManager *(^)(NSString *test))test
{
    return ^(NSString *test)
    {
        if (self.label) {
            self.label.text = test;
        }
        if (self.textfield) {
            self.textfield.text = test;
        }
        
        return self;
    };
}


- (HwwCreateManager * _Nonnull (^)(NSTextAlignment textAlignment))textAlignment
{
    return ^(NSTextAlignment textAlignment)
    {
        if (self.label) {
            self.label.textAlignment = textAlignment;
        }
        if (self.button) {
            self.button.titleLabel.textAlignment = textAlignment;
        }
        if (self.textfield) {
            self.textfield.textAlignment = textAlignment;
        }
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIFont * _Nonnull font))font
{
    return ^(UIFont *font)
    {
        if (self.label) {
            self.label.font = font;
        }
        if (self.button) {
            self.button.titleLabel.font = font;
        }
        if (self.textfield) {
            self.textfield.font = font;
        }
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(CGFloat size))size
{
    return ^(CGFloat size)
    {
        if (self.label) {
            self.label.font = [UIFont systemFontOfSize:size];
        }
        if (self.button) {
            self.button.titleLabel.font = [UIFont systemFontOfSize:size];
        }
        if (self.textfield) {
            self.textfield.font = [UIFont systemFontOfSize:size];
        }
        
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIColor * _Nonnull testColor))testColor
{
    return ^(UIColor* testColor)
    {
        if (self.label) {
            self.label.textColor =testColor;
        }
        if (self.textfield) {
            self.textfield.textColor = testColor;
        }
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(NSLineBreakMode lineBreakMode))lineBreakMode
{
    return ^(NSLineBreakMode lineBreakMode)
    {
        self.label.lineBreakMode = lineBreakMode;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(NSInteger))numberOfLines
{
    return ^(NSInteger numberOfLines)
    {
        self.label.numberOfLines = numberOfLines;
        return self;
    };
}


- (HwwCreateManager * _Nonnull (^)(BOOL))highLighted
{
    return ^(BOOL highLighted)
    {
        self.label.highlighted = highLighted;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIColor * _Nonnull))shadowColor
{
    return ^(UIColor *shadowColor)
    {
        self.label.shadowColor = shadowColor;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(CGSize shadowOffset))shadowOffset
{
    return ^(CGSize shadowOffset)
    {
        self.label.shadowOffset = shadowOffset;
        return self;
    };
}


//************************************************************************************************************************************************************
- (HwwCreateManager * _Nonnull (^)(UIImage * _Nonnull))image
{
    return ^(UIImage* image)
    {
        self.imageView.image = image;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIImage * _Nonnull))highlightedImage
{
    return ^(UIImage* highlightedImage)
    {
        self.imageView.highlightedImage = highlightedImage;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(NSArray * _Nonnull))animationImages
{
    return ^(NSArray* animationImages)
    {
        [self.imageView setAnimationImages:animationImages];
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(NSArray * _Nonnull))highlightedAnimationImages
{
    return ^(NSArray* highlightedAnimationImages)
       {
           [self.imageView setHighlightedAnimationImages:highlightedAnimationImages];
           return self;
       };
}

- (HwwCreateManager * _Nonnull (^)(CGFloat))animationDuration
{
    return ^(CGFloat animationDuration)
    {
        [self.imageView setAnimationDuration:animationDuration];
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(CGFloat))animationRepeatCount
{
    return ^(CGFloat animationDuration)
       {
           [self.imageView setAnimationRepeatCount:animationDuration];
           return self;
       };
}

- (HwwCreateManager * _Nonnull (^)(BOOL userInteractionEnabled))userInteractionEnabled
{
    return ^(BOOL userInteractionEnabled)
    {
        self.imageView.userInteractionEnabled = userInteractionEnabled;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(BOOL))imagehighlighted
{
    return ^(BOOL imagehighlighted)
    {
        [self.imageView setHighlighted:imagehighlighted];
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIViewContentMode))contentMode
{
    return ^(UIViewContentMode contentMode)
    {
        self.imageView.contentMode = contentMode;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(BOOL))clipsToBounds
{
    return ^(BOOL clipsToBounds)
    {
        self.imageView.clipsToBounds = clipsToBounds;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(id _Nonnull delegate, NSString * _Nonnull selector))gestures
{
    return ^(id delegate,NSString *selector)
    {
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:delegate action:NSSelectorFromString(selector)];
        [self.imageView addGestureRecognizer:tap];
        return self;
    };
}

//****************************************************************************************************************************************************************
- (HwwCreateManager * _Nonnull (^)(UIButtonType))buttontype
{
    return ^(UIButtonType buttontype)
    {
        self.button = [UIButton buttonWithType:buttontype];
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIImage * _Nonnull backgroundImage, UIControlState state))backgroundImage
{
    return ^(UIImage *backgroundImage,UIControlState state)
    {
        [self.button setBackgroundImage:backgroundImage forState:state];
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIImage * _Nonnull buttonimage, UIControlState state))buttonimage
{
    return ^(UIImage *buttonimage,UIControlState state)
    {
        [self.button setImage:buttonimage forState:state];
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIEdgeInsets imageEdgeInsets))imageEdgeInsets
{
    return ^(UIEdgeInsets imageEdgeInsets)
    {
        self.button.imageEdgeInsets = imageEdgeInsets;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIEdgeInsets titleEdgeInsets))titleEdgeInsets
{
 return ^(UIEdgeInsets titleEdgeInsets)
    {
        self.button.titleEdgeInsets = titleEdgeInsets;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(NSString * _Nonnull title, UIControlState state))title
{
    return ^(NSString *title,UIControlState state)
    {
        [self.button setTitle:title forState:state];
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(BOOL))showsTouchWhenHighlighted
{
    return ^(BOOL showsTouchWhenHighlighted)
    {
        self.button.showsTouchWhenHighlighted = showsTouchWhenHighlighted;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIColor * _Nonnull, UIControlState))titlecolor
{
    return ^(UIColor *titlecolor,UIControlState state)
    {
        [self.button setTitleColor:titlecolor forState:state];
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIControlContentHorizontalAlignment contentHorizontalAlignment))contentHorizontalAlignment
{
    return ^(UIControlContentHorizontalAlignment contentHorizontalAlignment)
    {
        self.button.contentHorizontalAlignment = contentHorizontalAlignment;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIControlContentVerticalAlignment contentVerticalAlignment))contentVerticalAlignment
{
    return ^(UIControlContentVerticalAlignment contentVerticalAlignment){
        self.button.contentVerticalAlignment = contentVerticalAlignment;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(NSString * _Nonnull,id _Nonnull delegate, UIControlEvents))target
{
    return ^(NSString *selector,id delegate,UIControlEvents event)
    {
        if (self.button) {
            [self.button addTarget:delegate action:NSSelectorFromString(selector) forControlEvents:event];
        }
        return self;
    };
}

//****************************************************************************************************************************************************************
- (HwwCreateManager * _Nonnull (^)(UITextBorderStyle))borderStyle
{
    return ^(UITextBorderStyle borderStyle)
    {
        self.textfield.borderStyle = borderStyle;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIImage * _Nonnull background))background
{
    return ^(UIImage *background)
    {
        self.textfield.background = background;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIImage * _Nonnull disabledBackground))disabledBackground
{
    return ^(UIImage *disabledBackground)
    {
        self.textfield.disabledBackground = disabledBackground;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(NSString * _Nonnull placeholder))placeholder
{
    return ^(NSString *placeholder)
    {
        self.textfield.placeholder = placeholder;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UITextFieldViewMode clearButtonMode))clearButtonMode
{
    return ^(UITextFieldViewMode clearButtonMode)
    {
        self.textfield.clearButtonMode = clearButtonMode;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(BOOL secureTextEntry))secureTextEntry
{
    return ^(BOOL secureTextEntry)
    {
        self.textfield.secureTextEntry = secureTextEntry;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UITextAutocorrectionType autocorrectionType))autocorrectionType
{
    return ^(UITextAutocorrectionType autocorrectionType)
    {
        self.textfield.autocorrectionType = autocorrectionType;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(BOOL clearsOnBeginEditing))clearsOnBeginEditing
{
    return ^(BOOL clearsOnBeginEditing)
    {
        self.textfield.clearsOnBeginEditing = clearsOnBeginEditing;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(BOOL adjustsFontSizeToFitWidth))adjustsFontSizeToFitWidth
{
    return ^(BOOL adjustsFontSizeToFitWidth)
    {
        self.textfield.adjustsFontSizeToFitWidth = adjustsFontSizeToFitWidth;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(CGFloat))minimumFontSize
{
    return ^(CGFloat minimumFontSize)
    {
        self.textfield.minimumFontSize = minimumFontSize;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIKeyboardType))keyboardType
{
    return ^(UIKeyboardType keyboardType)
    {
        self.textfield.keyboardType = keyboardType;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UITextAutocapitalizationType autocapitalizationType))autocapitalizationType
{
    return ^(UITextAutocapitalizationType autocapitalizationType)
    {
        self.textfield.autocapitalizationType = autocapitalizationType;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIReturnKeyType returnKeyType))returnKeyType
{
    return ^(UIReturnKeyType returnKeyType)
    {
        self.textfield.returnKeyType = returnKeyType;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(UIKeyboardAppearance keyboardAppearance))keyboardAppearance
{
    return ^(UIKeyboardAppearance keyboardAppearance)
    {
        self.textfield.keyboardAppearance = keyboardAppearance;
        return self;
    };
}

- (HwwCreateManager * _Nonnull (^)(id<UITextFieldDelegate> _Nonnull delegate))delegate
{
    return ^(id delegate)
    {
        self.textfield.delegate = delegate;
        return self;
    };
}
@end

